home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / comms / other / rxsocket / examples / tcp.rexx < prev    next >
OS/2 REXX Batch file  |  1999-06-14  |  2KB  |  92 lines

  1. /*
  2.                      shows how to use CreateIP() and CreateTCP()
  3.  
  4.                        THIS IS FOR EDUCATIONAL PORPOUSE ONLY!!!
  5.                               DON'T ASK WHAT IT IS FOR.
  6.                                DON'T EMAIL ME ABOUT IT.
  7.                  I DON'T ASSUME ANY RESPONSABILITY ABOUT USING OF IT.
  8. */
  9.  
  10. l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  11. if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then exit
  12.  
  13. prg=ProgramName("NOEXT")
  14.  
  15. if ~RMH_ReadArgs("FROM/A,TO/A,PORT/A/N") then do
  16.     call PrintFault(IoErr(),prg)
  17.     exit
  18. end
  19.  
  20. if parm.2.value<1 | parm.2.value>65535 then do
  21.     say "port '"parm.2.value"' not valid"
  22.     exit
  23. end
  24.  
  25. source = resolve(parm.0.value)
  26. if source==-1 then do
  27.     say "from host '"parm.0.value"' not found"
  28.     exit
  29. end
  30.  
  31. dest = resolve(parm.1.value)
  32. if dest==-1 then do
  33.     say "to host '"parm.1.value"' not found"
  34.     exit
  35. end
  36.  
  37. tcp.SPORT = 5000
  38. tcp.DPORT = parm.2.value
  39. tcp.SEQ      = 1
  40. tcp.ACK      = 0
  41. tcp.OFF      = 5
  42. tcp.FLAGS = 0
  43. tcp.WIN      = 21
  44. tcp.URP      = 1
  45. tcp.SRC      = source
  46. tcp.DST      = dest
  47.  
  48.  
  49. SIZEOFIP = 20
  50. ip.V   = 4
  51. ip.HL  = 5
  52. ip.TOS = 0
  53. ip.LEN = SIZEOFIP+length(tcpp)
  54. ip.ID  = 100
  55. ip.OFF = 0
  56. ip.TTL = 65
  57. ip.P   = 6
  58. ip.SUM = 0
  59. ip.SRC = source
  60. ip.DST = dest
  61.  
  62. sock = socket("INET","RAW","TCP")
  63. if sock<0 then do
  64.     say "no socket"
  65.     exit
  66. end
  67.  
  68. if setsockopt(sock,"IP","HDRINCL",1)<0 then do
  69.     say "no IP HDRINCL"
  70.     exit
  71. end
  72.  
  73. remote.addrfamily = "INET"
  74. remote.addraddr   = dest
  75.  
  76. do i=0 to 255
  77.     packet = createPacket(i);
  78.     res = sendto(sock,packet,0,"REMOTE")
  79.     if res==-1 then do
  80.         say res Errno()
  81.         exit
  82.     end
  83. end
  84. exit
  85.  
  86. createPacket: PROCEDURE EXPOSE ip. tcp.
  87. parse arg f
  88.     tcp.FLAGS = f
  89.     ipp = CreateIP("IP")
  90.     tcpp = CreateTCP("TCP")
  91.     return ipp || tcpp
  92.